package cn.maihe.elg.operation.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.web.client.RestTemplate;


import java.util.Collections;

@Configuration
public class RestTemplateConfig {

    @Bean("citicRestTemplate")
    public RestTemplate citicRestTemplate(CiticBankConfig citicBankConfig) {
        SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
        factory.setConnectTimeout(citicBankConfig.getConnectTimeout());
        factory.setReadTimeout(citicBankConfig.getReadTimeout());

        RestTemplate restTemplate = new RestTemplate(factory);
        restTemplate.setMessageConverters(Collections.singletonList(new ByteArrayHttpMessageConverter()));

        return restTemplate;
    }
}